define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Shopmsg, $stateParams,$ionicModal, GoDialog) {
		
		$scope.$on('$ionicView.afterEnter', function(){
			$scope.store_id = $stateParams.store_id;
			$scope.init_data();
		},false);
		
		//初始化页面
		$scope.init_data = function() {
			Shopmsg.get_shopmsg($scope.store_id, function(data) {
//				console.log( data)
				if(data != null)
					$scope.data = data;
				else
					$scope.data = new Object();
			})
		}
		
		$ionicModal.fromTemplateUrl("templates/modal/shop_announcement.html", {
			scope: $scope,
			animation: "slide-in-up"
		}).then(function(modal) {
			$scope.modal_shopnotice = modal;
		});
		//打开
		$scope.openModal_shopnotice = function(index) {
			$scope.notice = $scope.data.notice[index].notice;
			if(!$scope.notice){
				GoDialog.alert("提示","该店铺公告没有内容详情！");
				return ;
			}
			$scope.modal_shopnotice.show();
		}
		//隐藏
		$scope.closeModal_shopnotice = function() {
			$scope.modal_shopnotice.hide();
		}
		
		
	}

	controller.$inject = ['$scope', 'Shopmsg', '$stateParams','$ionicModal','GoDialog'];

	return app.registerController("shopmsgctrl",controller);
});